package com.yeyks.controller.member;


import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.annotation.NeedToken;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.param.MemberCardGiftInfoDownloadParam;
import com.yeyks.common.param.MemberCardGiftInfoParam;
import com.yeyks.common.param.MemberCardGiftUpdateParam;
import com.yeyks.common.result.MemberCardGiftDownloadResult;
import com.yeyks.common.utils.excel.ExcelUtil;
import com.yeyks.commonReference.service.vip.MemberCardGiftInfoService;
import com.yeyks.web.AccountUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 会员卡购买用户信息登记表 前端控制器
 * </p>
 *
 * @author Administrator
 */
@Api(tags = "会员卡购买用户信息")
@RestController
@RequestMapping("/ajax/memberCardGiftInfo")
public class MemberCardGiftInfoController {

    @Autowired
    private MemberCardGiftInfoService memberCardGiftInfoService;

    /**
     * v3.4.a
     */
    @NeedToken
    @ApiOperation(value = "分页查询会员卡购买用户信息")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public AjaxResponseBody selectPageList(@Validated MemberCardGiftInfoParam param) {

        AccountInfo loginUser = AccountUtils.getLoginUser();
        return memberCardGiftInfoService.selectPageList(param, loginUser);
    }


    /**
     * 导出订单
     *
     * @param response 响应
     */
    @NeedToken
    @CrossOrigin
    @ApiOperation(value = "导出VIP卡支付订单", notes = "导出VIP卡支付订单")
    @PostMapping(value = "/downMemberCardGift")
    public void downMemberCardGift(@Validated MemberCardGiftInfoDownloadParam param, HttpServletResponse response) {

        AccountInfo loginUser = AccountUtils.getLoginUser();
        List<MemberCardGiftDownloadResult> memberCardGiftDownloadResultList = memberCardGiftInfoService.selectListByParam(param,
                loginUser);
        ExcelUtil.disposeWriteExcelWithSheets(response, memberCardGiftDownloadResultList, new MemberCardGiftDownloadResult());
    }

    @NeedToken
    @ApiOperation(value = "确认发货", notes = "确认VIP卡发货")
    @PostMapping(value = "/confirmSendCard")
    public AjaxResponseBody confirmSendCard(@Validated MemberCardGiftUpdateParam param) {

        AccountInfo loginUser = AccountUtils.getLoginUser();
        return memberCardGiftInfoService.confirmSendCard(param);
    }

}
